//
//  CMDetailFoodView.m
//  项目三
//
//  Created by rimi1 on 2016/11/26.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "CommentFootView.h"

static NSInteger spacing_ = 20;

@implementation CommentFootView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.back];
        [self addSubview:self.collect];
        [self addSubview:self.textField];
        [self addSubview:self.line];
        [self addSubview:self.sure];
    }
    return self;
}

- (void)respondsToButton:(UIButton *)sender {
    if (self.buttonBlock) {
        self.buttonBlock(sender);
    }
}

#pragma mark - get

- (UIButton *)back {
    
    if (!_back) {
        
        _back = [[UIButton alloc] initWithFrame:CGRectMake(WXQAdaptionWidth(spacing_/4), 0, self.bounds.size.height, self.bounds.size.height)];
        _back.tag = 100;
        [_back addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        [_back setImage:[UIImage imageNamed:@"黑色返回"] forState:UIControlStateNormal];
        
    }
    return _back;
}

- (UIButton *)collect {
    
    if (!_collect) {
        
        _collect = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.back.frame) + spacing_/4, 0, self.bounds.size.height, self.bounds.size.height)];
        _collect.tag = 101;
        [_collect addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        [_collect setImage:[UIImage imageNamed:@"未收藏"] forState:UIControlStateNormal];
        [_collect setImage:[UIImage imageNamed:@"已收藏"] forState:UIControlStateSelected];
        
    }
    return _collect;
}

- (UITextField *)textField {
    
    if (!_textField) {
        
        CGFloat x = CGRectGetMaxX(self.collect.frame) + 5;
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(x, CGRectGetMinY(self.collect.frame), kWIDTH - x - CGRectGetWidth(self.sure.bounds) - spacing_/2 - spacing_/4, 44)];
        
    }
    return _textField;
}

- (UIView *)line {
    
    if (!_line) {
        
        _line = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.textField.frame), CGRectGetMaxY(self.textField.frame) - 5, CGRectGetWidth(self.textField.bounds), 1)];
        _line.backgroundColor = [UIColor orangeColor];
        
    }
    return _line;
}

- (UIButton *)sure {
    
    if (!_sure) {
        
        CGFloat width = 55;
        _sure = [[UIButton alloc] initWithFrame:CGRectMake(kWIDTH - spacing_/2 - width, 6, width, 35)];
        _sure.layer.cornerRadius = 5;
        _sure.backgroundColor = [UIColor orangeColor];
        [_sure setTitle:@"评论" forState:UIControlStateNormal];
        _sure.tag = 102;
        [_sure addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _sure;
}

@end












